package guoan.service;

import guoan.domain.Customer;
import guoan.repository.CustomerRepository;
import guoan.utils.CommonUtils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * ClassName: CustomerService <br/>
 * 客服人员service <br/>
 * date: 2015年4月13日 下午2:04:02 <br/>
 *
 * @author he.sun
 * @version
 * @since JDK 1.7
 */
@Service
@Transactional
public class CustomerService extends PageSerivce<Customer> {
	protected final Logger log = LoggerFactory.getLogger(getClass());

	@Autowired
	private CustomerRepository customerRepository;

	/**
	 * login:登陆验证 <br/>
	 *
	 * @author he.sun
	 * @param uname
	 * @param upass
	 * @return
	 */
	public Customer login(String uname, String upass) {
		// TODO Auto-generated method stub

		log.debug("登陆业务处理：{uname:{},upass:{}}", uname, upass);
		upass = CommonUtils.md5(upass.trim());
		log.debug("登陆业务处理，密码加密：{upass:{}}", upass);

		Customer customer = customerRepository.findByCustomerLoginNameAndCustomerPassword(uname, upass);
		log.debug("登陆业务处理，登陆结果：{}", customer);

		return customer;
	}

	public void changePSW(String psw) {
		customerRepository.changePSW(CommonUtils.md5(psw.trim()));
	}
}
